// @ts-nocheck

export default {
  async bostonClickType({} = {}) {
    const self = this;
    await self.vick3dMapPostMessage({
      from: 'vick3dMapFather',
      type: 'newFunction',
      key: 'newFunction',
      value: `
        if (window.vickTilesetCollection == null) {
          window.vickTilesetCollection = {};
        }
        if (window.vickTilesetCollection['波士顿'] == null) {
          // token
          Cesium.Ion.defaultAccessToken =
            'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI1NzQ1ZDNkMS1hMjE4LTRjNTUtODVjYi02ZWQzYWM5MWUyNmEiLCJpZCI6MjU1NzcsImlhdCI6MTczNzQyNDQ1M30.2mHGCSN4-xSTpG4bZrMK33CVzCbdGDLpzjlRBdhxJ54';
          // 添加 波士顿
          const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(354759);
          // 拉高 波士顿 35米
          const cartographicOld = Cesium.Cartographic.fromCartesian(tileset.boundingSphere.center);
          let cartographic = cartographicOld;
          const surface = Cesium.Cartesian3.fromRadians(cartographicOld.longitude, cartographicOld.latitude, 0.0);
          const offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 35.0);
          const translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
          tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
          window.vickTilesetCollection['波士顿'] = tileset;
          // 添加 波士顿
          viewer.scene.primitives.add(tileset);
          // 飞行 到 波士顿
          viewer.camera.flyToBoundingSphere(tileset.boundingSphere);
        } else {
          const tileset = window.vickTilesetCollection['波士顿'];
          viewer.camera.flyToBoundingSphere(tileset.boundingSphere);
        }
      `
    });
  }
};
